home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <dos.h>
-
- union REGS inreg,outreg;
-
-
-
-
- /* ╔══ FUNCTION DECLARATIONS ═══════════════════════╗ */
-
- void biosbox(int, int, int, int, int, int);
- void ccls(int);
- void cls(void);
- void cursor(int);
- void gotoxy(int, int);
- void put_ca(char, int, int);
- void put_cai(char, int);
- void put_str(char *, int);
- int scroll(int, int, int, int, int, int);
- void smode(int);
- int vmode(void);
- char what_xy(int, int);
- int where_x(void);
- int where_y(void);
-
- /* ╚══ FUNCTION DECLARATIONS ═══════════════════════╝ */
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : biosbox(upCOL,upROW,lowCOL,lowROW,attr,type); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ draws box and clears center to a specified attribute (w/bios calls) ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : biosbox(upCOL,upROW,lowCOL,lowROW,attr,type); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void biosbox(upCOL,upROW,lowCOL,lowROW,attr,type)
- int upCOL,upROW,lowCOL,lowROW,attr,type;
- {
- register int x;
- int wide;
- char UL,UR,LL,LR,SD,TB;
-
- switch(type) {
- case 1 : /* single line box */
- UL = 218;
- UR = 191;
- LL = 192;
- LR = 217;
- SD = 179;
- TB = 196;
- break;
-
- case 2 : /* double line box */
- UL = 201;
- UR = 187;
- LL = 200;
- LR = 188;
- SD = 186;
- TB = 205;
- break;
-
- case 3 : /* double sides - single top */
- UL = 214;
- UR = 183;
- LL = 211;
- LR = 189;
- SD = 186;
- TB = 196;
- break;
-
- case 4 :
- UL = 213; /* single sides - double top */
- UR = 184;
- LL = 212;
- LR = 190;
- SD = 179;
- TB = 205;
- break;
-
- case 5 :
- UL = 219; /* bold box */
- UR = 219;
- LL = 219;
- LR = 219;
- SD = 219;
- TB = 219;
- break;
-
- default:
- UL = 218;
- UR = 191;
- LL = 192;
- LR = 217;
- SD = 179;
- TB = 196;
- }
- wide = (lowCOL + 1 ) - upCOL;
-
- for(x = upROW;x <= lowROW;x++) {
- gotoxy(upCOL,x);
- put_ca(' ',attr,wide);
- }
-
- gotoxy(upCOL,upROW);
- put_ca(TB,attr,wide);
- gotoxy(upCOL,lowROW);
- put_ca(TB,attr,wide);
-
- gotoxy(upCOL,upROW);
- put_ca(UL,attr,1);
-
- gotoxy(lowCOL,upROW);
- put_ca(UR,attr,1);
-
-
- gotoxy(upCOL,lowROW);
- put_ca(LL,attr,1);
-
- gotoxy(lowCOL,lowROW);
- put_ca(LR,attr,1);
-
- for(x = upROW+1;x < lowROW;x++) {
- gotoxy(upCOL,x);
- put_ca(SD,attr,1);
- gotoxy(lowCOL,x);
- put_ca(SD,attr,1);
- }
- }
-
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : ccls(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ clears the screen and sets the attribute (ex: ccls(7);) ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : ccls(attribute); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void ccls(attr)
- int attr;
- {
- inreg.h.ah = 6;
- inreg.h.al = 0;
- inreg.h.bh = attr;
- inreg.h.ch = 0;
- inreg.h.cl = 0;
- inreg.h.dh = 24;
- inreg.h.dl =79;
- int86(0x10, &inreg, &outreg);
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : cls(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ clears the screen and homes the cursor ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : cls(); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void cls(void)
- {
- int mode;
-
- mode = vmode(); /* read current video mode */
- smode(mode); /* set the same video mode */
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : cursor(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ turns the cursor off ║ */
- /* ║ also sets cursor to normal size [ _ ] or full size [ █ ] ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : cursor(type); ║ */
- /* ║ ║ */
- /* ║ type 0 = cursor off ║ */
- /* ║ 1 = normal cursor ║ */
- /* ║ 2 = full size ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void cursor(type)
- int type;
- {
- unsigned int equip;
-
- inreg.h.ah = 1;
-
- equip=biosequip();
- if((equip & 0x30)==0x30) /* If monochrome card value will be 0x30 */
- {
- if (type == 0)
- inreg.x.cx = 0x0F0F;
- else if (type == 1)
- inreg.x.cx = 0x0C0D;
- else if (type == 2)
- inreg.x.cx = 0x010D;
- }
- else /* color */
- {
- if (type == 0)
- inreg.x.cx = 0x0F0F;
- else if (type == 1)
- inreg.x.cx = 0x0607;
- else if (type == 2)
- inreg.x.cx = 0x0107;
- }
-
- int86(0x10, &inreg, &outreg);
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : gotoxy(); (x = col y = row) ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ positions the cursor to x,y ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : gotoxy(x,y); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void gotoxy(col,row)
- int col,row;
- {
- inreg.h.ah = 2;
- inreg.h.dl = col;
- inreg.h.dh = row;
- inreg.h.bh = 0;
- int86(0x10, &inreg, &outreg);
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : put_ca(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ use bios to a print character and attribute to the screen for ║ */
- /* ║ specified number of times (repeats) ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : put_ca(char, attr, num); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void put_ca(chr,attr,num)
- char chr;
- int attr,num;
- {
- inreg.h.ah = 9;
- inreg.h.al = chr;
- inreg.h.bh = 0;
- inreg.h.bl = attr;
- inreg.x.cx = num;
-
- int86(0x10,&inreg,&outreg);
- }
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : put_cai(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ use bios to a print character and attribute to the screen and ║ */
- /* ║ increment the cursor ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : put_cai(char, attr); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void put_cai(chr,attr)
- char chr;
- int attr;
- {
- int x,y;
-
- inreg.h.ah = 9;
- inreg.h.al = chr;
- inreg.h.bh = 0;
- inreg.h.bl = attr;
- inreg.x.cx = 1;
- int86(0x10,&inreg,&outreg);
-
- x = where_x();
- y = where_y();
- x++;
- if(x > 79) {
- x = 0;
- y++;
- }
- if(y > 24) {
- scroll(0,0,79,24,1,0);
- y = 24;
- }
- gotoxy(x,y);
- }
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : put_str(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ use bios to a print a string and attribute to the screen ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : put_str(string,attr); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void put_str(str, attr)
- char *str;
- int attr;
- {
- register int i;
- for(i=0;*str != '\0';++str,++i)
- put_cai(*str,attr);
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : scroll(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ scroll window up/down ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : scroll(x1,y1,x2,y2,num,dir); ║ */
- /* ║ x1 = left column ║ */
- /* ║ y1 = upper row ║ */
- /* ║ x2 = right column ║ */
- /* ║ y2 = lower row ║ */
- /* ║ num = lines to scroll ║ */
- /* ║ dir = direction of scroll (0=up 1=down) ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- int scroll(x1,y1,x2,y2,num,dir)
- int x1,y1,x2,y2,num,dir;
- {
-
- inreg.h.ah = 6 + dir;
- inreg.h.al = num;
- inreg.h.bh = 7;
- inreg.h.ch = y1;
- inreg.h.cl = x1;
- inreg.h.dh = y2;
- inreg.h.dl = x2;
-
- int86(0x10,&inreg,&outreg);
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : smode(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ sets the video mode ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : smode(7); ║ */
- /* ║ ║ */
- /* ║ Returns : nothing ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- void smode(int mode)
- {
- inreg.h.ah = 0;
- inreg.h.al = mode;
- int86(0x10, &inreg, &outreg);
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : vmode(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ returns the current video mode ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : a = vmode(); ║ */
- /* ║ ║ */
- /* ║ Returns : video mode to specified variable ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- int vmode(void)
- {
- inreg.h.ah = 15;
- int86(0x10, &inreg, &outreg);
- return outreg.h.al;
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : what_xy(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ returns the character at x,y to a specified variable (x=col y=row) ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : a = what_xy(x,y); ║ */
- /* ║ ║ */
- /* ║ Returns : Character at x,y ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- char what_xy(x1,y1)
- int x1,y1;
- {
- gotoxy (x1,y1);
- inreg.h.ah = 8;
- inreg.h.bh = 0;
-
- int86(0x10,&inreg,&outreg);
-
- return(outreg.h.al);
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : where_x(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ locates the column position of the cursor ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : x = where_x(); ║ */
- /* ║ ║ */
- /* ║ Returns : the column position (x) ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- int where_x(void)
- {
- unsigned int x;
- inreg.h.ah = 3;
- inreg.h.bh = 0;
- int86(0x10, &inreg, &outreg);
- x = outreg.h.dl;
-
- return x;
- }
-
-
- /* ╔══════════════════════════════════════════════════════════════════════╗ */
- /* ║ Function : where_y(); ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ locates the row position of the cursor ║ */
- /* ╠══════════════════════════════════════════════════════════════════════╣ */
- /* ║ Usage : y = where_y(); ║ */
- /* ║ ║ */
- /* ║ Returns : the row position (y) ║ */
- /* ╚══════════════════════════════════════════════════════════════════════╝ */
- int where_y(void)
- {
- unsigned int y;
- inreg.h.ah = 3;
- inreg.h.bh = 0;
- int86(0x10, &inreg, &outreg);
- y = outreg.h.dh;
-
- return y;
- }
-
-
-